const express = require('express')
const app = express()
const bodyParser = require('body-parser')

app.use(bodyParser.json()) // body-parser  解析json格式数据
app.use(bodyParser.urlencoded({
  extended: true
}))

/*为app添加中间件处理跨域请求*/
app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
});

const router = express.Router()

app.get('/', (req, res) => {
  res.send('hello world')
})

// 访问地址：http://localhost:8888/api/xxx
app.use('/api', require('./mock'));


app.listen(8888)